<!--
 * @Author: your name
 * @Date: 2022-02-13 15:18:58
-->
<template>
  <div class="card-container">
    <el-row :gutter="20">
      <el-col
        v-for="item in list"
        :key="item.id"
        :xs="24"
        :sm="24"
        :md="24"
        :lg="8"
        :xl="8"
      >
        <el-card
          shadow="hover"
          :body-style="{ padding: '0px', position: 'static' }"
        >
          <vab-magnifier :url="item.img" type="circle"></vab-magnifier>
          <div class="card-title">{{ item.title }}</div>
          <div class="card-description">{{ item.description }}</div>
          <div class="card-datetime">{{ item.datetime }}</div>
        </el-card>
      </el-col>
      <el-col :span="24">
        <el-pagination
          :background="background"
          :current-page="queryForm.pageNo"
          :page-size="queryForm.pageSize"
          :page-sizes="[10, 20, 30, 40, 50, 100]"
          :layout="layout"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        ></el-pagination>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import VabMagnifier from '@/plugins/vabMagnifier.js'
  import { getList } from '@/api/card'

  export default {
    name: 'Card',
    components: {
      VabMagnifier,
    },
    data() {
      return {
        list: [],
        total: 0,
        layout: 'total, sizes, prev, pager, next, jumper',
        background: true,
        queryForm: {
          pageNo: 1,
          pageSize: 20,
          title: '',
        },
      }
    },
    created() {
      this.fetchList()
    },
    methods: {
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchList()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchList()
      },
      async fetchList() {
        const res = await getList(this.queryForm)
        if (res.code === 200) {
          this.list = res.data
          this.total = res.totalCount
        }
      },
    },
  }
</script>
<style lang="scss" scoped>
  .card-container {
    padding: 0 0 20px 0 !important;
    background: #f6f8f9 !important;
    .img-container {
      width: 100%;
      height: 228px;
      img {
        height: 100%;
      }
    }
    .card-title {
      margin: 20px 20px 10px 20px;
      font-size: 16px;
      font-weight: 700;
    }
    .card-description {
      margin: 0 20px 10px 20px;
    }
    .card-datetime {
      margin: 0 20px 10px 20px;
      color: rgba(81, 90, 110, 0.6);
    }
  }
</style>
